package com.cameron.serviceedu.controller;


import com.cameron.serviceedu.service.EduSubjectService;
import com.cameron.utils.Result;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author cameron
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/service/edu-subject")
@CrossOrigin
public class EduSubjectController {

    @Resource
    private EduSubjectService eduSubjectService;

    @PostMapping("addSubject")
    public Result addSubject(MultipartFile file) {
        return eduSubjectService.saveSubject(file) ? Result.ok() : Result.error();
    }

    @GetMapping("getAll")
    public Result getAll() {
        return eduSubjectService.getAll();
    }

    @GetMapping("subject/name/{id}")
    public Result getSubjectName(@PathVariable String id) {
        String title = eduSubjectService.getById(id).getTitle();
        return Result.ok().data("subjectName", title);
    }
}

